package com.yixuan.mt.console.controller;

import com.fasterxml.jackson.core.JsonProcessingException;
import  com.yixuan.mt.common.exception.HttpBadRequestException;
import com.yixuan.mt.common.response.Result;
import com.yixuan.mt.common.request.LoginRequest;
import com.yixuan.mt.common.service.AuthService;
import jakarta.validation.Valid;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RequestMapping("/op")
@RestController
public class AuthController {

    @Autowired
    private AuthService authService;

    /**
     * 登录
     * @throws JsonProcessingException JsonProcessingException
     * @throws HttpBadRequestException 用户名或密码错误
     */
    @PostMapping("/login")
    public Result<String> login(@Valid @RequestBody LoginRequest loginRequest) throws JsonProcessingException {
        return Result.successWithMsg(authService.login(loginRequest), "登录成功！");
    }

}
